package work;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import utils.RabbitMQUtils;

import java.io.IOException;

/**
 * Customer1
 * 第一个消费者
 * @author 丛有志
 * @date 2020/11/19 9:00
 * <p>
 * 版本        修改时间        作者        修改内容
 * V1.0        2020/11/19     丛有志        初始版本
 */
public class Customer1 {
    public static void main(String[] args) throws IOException, InterruptedException {
        // 获取连接对象
        Connection connection = RabbitMQUtils.getConnection();
        // 获取通道
        Channel channel = connection.createChannel();
        channel.basicConsume("work",false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                try {
                    Thread.sleep(3000);
                    System.out.println("第一个消费者Work模型："+new String(body));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
